package ltd.hello.trik.snake;

import lombok.*;
import lombok.experimental.SuperBuilder;
import processing.core.PApplet;
import processing.core.PVector;

import static processing.core.PApplet.abs;

/**
 * +----------------------------------------------------------------------
 * |
 * +----------------------------------------------------------------------
 * | <a href="https://www.hellotrik.ltd">Copyright (c) 2024~2025 </a>.
 * +----------------------------------------------------------------------
 * | Licensed MIT
 * +----------------------------------------------------------------------
 * | 作者: 🦠 matrixg 👾 <hellotrik@foxmail.com>
 * | 日期: 2024/9/9
 * +----------------------------------------------------------------------
 */
@Getter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class Cell {
    public static PVector ToColor(PVector p){
        p.x=abs(p.x)*255;
        p.y=abs(p.y)*255;
        p.z=abs(p.z)*255;
        return p;
    }

    @NonNull
    protected PApplet applet;
    @Builder.Default
    protected PVector pos=new PVector();
    @Setter
    @Builder.Default
    protected float size=20;
    @Setter
    @Builder.Default
    protected PVector color=new PVector(255,255,255);


    public void show() {
        applet.pushMatrix();
        applet.translate(pos.x, pos.y, pos.z);
        applet.noStroke();
        applet.lights();
        applet.fill(color.x,color.y,color.z);
        applet.sphere(size/2);
        applet.popMatrix();
    }

    public Cell copy() {
        val cell = new Cell();
        copy(cell);
        return cell;
    }
    public void copy(Cell cell) {
        cell.pos=pos.copy();
        cell.size=size;
        cell.applet=applet;
        cell.color=color.copy();
    }

    public boolean collide(Cell cell) {
       return collide(cell.getPos());
    }
    public boolean collide(PVector cell) {
       return pos.equals(cell);
//       return floor(cell.x)==floor(pos.x)&&floor(cell.y)==floor(pos.y)&&floor(cell.z)==floor(pos.z);
    }
}
